import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class College {
    String name;
    List<String> majors;

    public College(String name) {
        this.name = name;
        this.majors = new ArrayList<>();
    }

    public void addMajor(String major) {
        if (majors.size() < 6) {
            majors.add(major);
        } else {
            System.out.println("每个高校最多只能添加6个专业！");
        }
    }

    @Override
    public String toString() {
        return name + "（专业：" + String.join(", ", majors) + "）";
    }
}

class Volunteer {
    College college;
    List<String> selectedMajors;

    public Volunteer(College college) {
        this.college = college;
        this.selectedMajors = new ArrayList<>();
    }

    public void selectMajor(String major) {
        if (college.majors.contains(major) && selectedMajors.size() < 6) {
            selectedMajors.add(major);
        } else {
            System.out.println("选择的专业无效或已超过6个！");
        }
    }

    @Override
    public String toString() {
        return "志愿：" + college.name + "（选择的专业：" + String.join(", ", selectedMajors) + "）";
    }
}

public class CollegeApplicationSystem {
    private static Scanner scanner = new Scanner(System.in);
    private static List<College> colleges = new ArrayList<>();
    private static List<Volunteer> volunteers = new ArrayList<>();
    private static String studentName;

    public static void main(String[] args) {
        // 初始化高校数据（这里只示例添加几所，实际可以从文件或数据库读取）
        addCollege("peking university");
        addCollege("tsinghua university");
        addCollege("bipt");
        // ... 添加其他高校

        // 输入学生 姓名
        System.out.print("请输入学生姓名: ");
        studentName = scanner.nextLine();

        // 填报志愿
        fillVolunteers();

        // 调整志愿顺序（简化处理，只提供打印功能，不实际调整）
        // 实际应用中，可以添加交换志愿的逻辑

        // 打印志愿填报表
        printVolunteerForm();

        scanner.close();
    }

    private static void addCollege(String name) {
        colleges.add(new College(name));
        // 这里可以添加专业，为了简化，只示例添加几个通用专业
        if (name.equals("peking university")) {
            addMajorsToCollege(name, "computer", "maths", "electrical", "economic control", "biomaterial");
        } else if (name.equals("tsinghua university")) {
            addMajorsToCollege(name, "computer", "maths", "electrical", "economic control", "biomaterial");
        } else if (name.equals("bipt")) {
            addMajorsToCollege(name, "computer", "maths", "electrical", "economic control", "biomaterial");
        }
        // ... 为其他高校添加专业
    }

    private static void addMajorsToCollege(String collegeName, String... majors) {
        for (String major : majors) {
            for (College college : colleges) {
                if (college.name.equals(collegeName)) {
                    college.addMajor(major);
                    break;
                }
            }
        }
    }

    private static void fillVolunteers() {
        for (int i = 1; i <= 30; i++) {
            System.out.println("填报第" + i + "个志愿（输入'0'结束填报）:");
            System.out.print("请输入高校名称: ");
            String collegeName = scanner.nextLine();
            if (collegeName.equals("0")) {
                break;
            }

            College college = null;
            for (College c : colleges) {
                if (c.name.equals(collegeName)) {
                    college = c;
                    break;
                }
            }

            if (college == null) {
                System.out.println("高校名称无效，请重新输入！");
                i--; // 无效输入，重新填报当前志愿
                continue;
            }

            Volunteer volunteer = new Volunteer(college);
            System.out.println("请输入选择的专业（输入'end'结束选择，最多6个）:");
            while (volunteer.selectedMajors.size() < 6) {
                System.out.print("请输入专业名称: ");
                String major = scanner.nextLine();
                if (major.equalsIgnoreCase("end")) {
                    break;
                }
                volunteer.selectMajor(major);
            }

            volunteers.add(volunteer);
        }
    }

    private static void printVolunteerForm() {
        System.out.println("\n" + studentName + "的志愿填报表:");
        for (int i = 0; i < volunteers.size(); i++) {
            System.out.println((i + 1) + ". " + volunteers.get(i));
        }
    }
}